/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useRef } from 'react';
import { message, Button } from 'antd';
import { PageContainer } from '@ant-design/pro-layout';
import { getRecordList } from '@/services/sms/examine';
import DragTable from '@/components/DragTable';
import ProTable, { ActionType } from '@ant-design/pro-table';
import { history, useLocation } from 'umi';
import type { Location } from 'umi';
import type { SmsExamineRecordListItem } from '@/components/_pages/sms/examine/_utils/type';
import { recordColumns } from '@/components/_pages/sms/examine/_utils';

const KbSmsRecordList = () => {
  const { query } = useLocation() as Location | any;
  const { cm_id } = query;
  const actionRef = useRef<ActionType>();

  const getList = async (values: any) => {
    const { current: page, pageSize } = values;
    const { code, data, msg } = await getRecordList({
      cm_id,
      page_num: page,
      page_size: pageSize,
    });
    if (code == 0) {
      return {
        total: data.total_count,
        data: data.list,
      };
    } else {
      message.error(msg);
      return { data: [] };
    }
  };

  return (
    <PageContainer>
      <DragTable>
        <ProTable<SmsExamineRecordListItem>
          rowKey='id'
          actionRef={actionRef}
          toolBarRender={false}
          columns={recordColumns}
          cardProps={{
            extra: [
              <Button key='back' onClick={history.goBack}>
                返回上一页
              </Button>,
            ],
          }}
          pagination={{
            pageSize: 20,
            showQuickJumper: false,
            showSizeChanger: false,
          }}
          request={getList}
          search={false}
        />
      </DragTable>
    </PageContainer>
  );
};

export default KbSmsRecordList;
